<?php
/**
 * Created by PhpStorm.
 * User: stupboy
 * Date: 2018/2/14
 * Time: 20:34
 */

namespace app\api\controller\passenger;

use app\api\logic\Driver;
use app\api\logic\Version;
use app\base\service\WechatPay;
use think\Db;
use app\base\service\Phone;
use app\api\model;
use think\Hook;
/**
 * @name【乘客接口】
 * @baseurl【passenger】
 * @file【passenger/Index.php】
 */
class Index extends Base
{
    /**
     * @name【选择乘车人】
     * @desc【选择乘车人】
     * @uri【change_department_passenger】
     * @method【post】
     * @param【
     * ptoken $ string $ token $ 校验码 $ 1
     * 】
     * @return【
     * code $ int $ number|1-1 $ 标识1-成功 0-失败#
     * msg $ string $  $ code=0，错误信息#
     * data $ string $ $ 列表 $ {"car_use_name":"晋江市机关单位","department_info":[{"department_id":2014,"name":"晋江市机关单位","passenger_info":[]},{"department_id":2015,"name":"青阳街道办事处","passenger_info":[]},{"department_id":2016,"name":"梅岭街道办事处","passenger_info":[{"passenger_name":"小白","passenger_phone":"15060816655"}]},{"department_id":2017,"name":"罗山街道办事处","passenger_info":[]},{"department_id":2018,"name":"西园街道办事处","passenger_info":[]},{"department_id":2019,"name":"晋江市集成电路科技投资有限责任公司","passenger_info":[]},{"department_id":2020,"name":"教育局","passenger_info":[]},{"department_id":2021,"name":"晋江市妇联","passenger_info":[{"passenger_name":"刘标","passenger_phone":"18105963806"}]},{"department_id":2022,"name":"晋江市人民检察院","passenger_info":[]},{"department_id":2023,"name":"晋江市人民法院","passenger_info":[]},{"department_id":2024,"name":"晋江市农业局","passenger_info":[]},{"department_id":2025,"name":"晋江市市政园林局","passenger_info":[]},{"department_id":2026,"name":"金龙旅游","passenger_info":[]},{"department_id":2027,"name":"金龙旅游","passenger_info":[]}]}
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function change_department_passenger()
    {
        // 代他人叫车权限
        if($this->passengerInfo['is_instead']==9){
            return $this->retError(143);
        }
        $data['data'] = (new model\Passenger())->getPassengerList($this->passengerInfo['passenger_id']);
        return $this->retSucc($data);
    }

    /**
     * @name【查询乘车人】
     * @desc【查询乘车人】
     * @uri【searchMan】
     * @method【post】
     * @param【
     * ptoken $ string $ token $ 校验码 $ 1 #
     * pname $ string $ 张 $ 查询关键词  $ 1$
     * 】
     * @return【
     * code $ int $ number|1-1 $ 标识1-成功 0-失败#
     * msg $ string $  $ code=0，错误信息#
     * data $ string $ $ 列表 $
     * 】
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function searchMan(){
        if($this->passengerInfo['is_instead']==9){
            return $this->retError(143);
        }
        $pname = input('pname','');
        if(empty($pname)){
            return $this->retError(145);
        }
        $data['data'] = (new model\Passenger())->getPassengerList($this->passengerInfo['passenger_id'], $pname,$this->passengerInfo['company_id']);
        return $this->retSucc($data);
    }

    /**
     * @name【支付类型】
     * @desc【支付类型】
     * @uri【getPayType】
     * @param【
     * ptoken $ string $ token $ 校验码 $ 1#
     * 】
     * @return【
     * code $ int $ number|1-1 $ 标识1-成功 0-失败#
     * msg $ string $  $ code=0，错误信息 #
     * 】
     */
    public function getPayType(){
        $data['data'] = [
//            1=>'个人支付',
            2=>'单位支付',
            3=>'财政支付',
            4=>'自有用车'
        ];
        return $this->retSucc($data);
    }

    /**
     * @name【公务-用车类型】
     * @desc【公务-用车类型】
     * @uri【use_car_type】
     * @param【
     * ptoken $ string $ token $ 校验码 $ 1#
     * 】
     * @return【
     * code $ int $ number|1-1 $ 标识1-成功 0-失败#
     * msg $ string $  $ code=0，错误信息
     * 】
     */
    public function use_car_type()
    {
        $info = config('base.use_types');
        if (!$info) {
            return $this->retError('暂无用车类型！');
        }
        $carUseId = $this->passengerInfo['company_id'];
        $isLaw    = Db::name('company')->where('company_id', $carUseId)->value('law_type');
        if ($isLaw == 1) {
            unset($info[1]);
        }
        return $this->retSucc(['data' => $info]);
    }

    /**
     * @name【包车计费信息-弃用】
     * @desc【包车计费信息-弃用】
     * @uri【car_type】
     * @method【post】
     * @param【
     * ptoken $ string $ token $ 校验码 $ 1#
     * type $ string $ 1 $ 类型。4：约组车，2：公务车，5：私包车，3：公包车 $ 1#
     * use_type $ int $ 1 $ 用车类型
     * 】
     * @return【
     * code $ int $ number|1-1 $ 标识1-成功 0-失败#
     * msg $ string $  $ code=0，错误信息
     * 】
     */
    public function car_type()
    {
        //选择包车的车型后  返回包车的计费信息
        //车辆类型，2：优选型，3：舒适型，4：豪华型，5：小巴，6：中巴，7：大巴，8：执法车
        //类型。4：约组车，2：公务车，5：私包车，3：公包车
        $p              = input('param.');
        $where['state'] = '1';
        $where['type']  = $p['type'];
        $useType        = input('use_type',0);
        if($useType==1){
            $carLimit = Db::name('car')->where('prop',3)->whereNull('delete_time')->column('car_type_id');
            $where['car_type_id'] = ['in',implode(',',$carLimit)];
        }
        $carTypes       = Db::name('car_type')
            ->where($where)
            ->whereNull('delete_time')
            ->field('car_type,seats,car_type_id,p_chartered_charge chartered_charge,chartered_km,chartered_hour')
            ->select();
        $rank           = [2=>1,3=>2,4=>3,9=>4,5=>5,6=>6,7=>7,8=>8];
        $info           = [];
        foreach ($carTypes as $k => $val) {
            $val['rank'] = $rank[$val['car_type']];
            if (empty($info[$val['seats']])) {
                $info[$val['seats']] = [
                    'car_type_id' => $val['car_type_id'],
                    'seats' => $val['seats'],
                    'car_type_info' => [$val]
                ];
            } else {
                $info[$val['seats']]['car_type_info'][] = $val;
            }
        }
        if ($info) {
            return $this->retSucc(['data'=>$info]);
        } else {
            return $this->retError('暂无车辆类型！');
        }
    }

    /**
     * @name【获取车型】
     * @desc【获取车型】
     * @uri【getCarType】
     * @method【post】
     * @param【
     *  ptoken $ string $ token $ 校验 $ 1 #
     *  go_type $ int $ 1  $ 2公务 3公务包车 4 约租车 5 包租车 $ 1 #
     *  use_type $ int $ 1 $ 用车类型,公务必填
     * 】
     * @return【
     * code $ int    $ number|1-1 $ 校验码#
     * msg  $ string $  $ 错误信息 #
     * data $ string $ $ 包车车型数据 $ {"2":{"name":"优选型","rank":1,"types":[{"car_type_id":140,"car_type":"2","type":"5","chartered_km":40,"chartered_charge":"150.00","chartered_hour":2,"seats":0},{"car_type_id":141,"car_type":"2","type":"5","chartered_km":100,"chartered_charge":"280.00","chartered_hour":4,"seats":0},{"car_type_id":142,"car_type":"2","type":"5","chartered_km":200,"chartered_charge":"480.00","chartered_hour":6,"seats":0},{"car_type_id":143,"car_type":"2","type":"5","chartered_km":300,"chartered_charge":"580.00","chartered_hour":10,"seats":0}]},"3":{"name":"舒适型","rank":2,"types":[{"car_type_id":144,"car_type":"3","type":"5","chartered_km":40,"chartered_charge":"150.00","chartered_hour":2,"seats":0},{"car_type_id":145,"car_type":"3","type":"5","chartered_km":100,"chartered_charge":"280.00","chartered_hour":4,"seats":0},{"car_type_id":146,"car_type":"3","type":"5","chartered_km":200,"chartered_charge":"480.00","chartered_hour":6,"seats":0},{"car_type_id":147,"car_type":"3","type":"5","chartered_km":300,"chartered_charge":"580.00","chartered_hour":10,"seats":0}]},"9":{"name":"商务型","rank":4,"types":[{"car_type_id":148,"car_type":"9","type":"5","chartered_km":40,"chartered_charge":"180.00","chartered_hour":2,"seats":0},{"car_type_id":149,"car_type":"9","type":"5","chartered_km":100,"chartered_charge":"380.00","chartered_hour":4,"seats":0},{"car_type_id":150,"car_type":"9","type":"5","chartered_km":200,"chartered_charge":"600.00","chartered_hour":6,"seats":0},{"car_type_id":151,"car_type":"9","type":"5","chartered_km":300,"chartered_charge":"750.00","chartered_hour":10,"seats":0}]}} #
     * data $ string $$ 普通车型数据 $ [{"car_type_id":133,"car_type":"3","type":"2","car_type_name":"舒适型","rank":2},{"car_type_id":130,"car_type":"6","type":"2","car_type_name":"小巴","rank":6},{"car_type_id":134,"car_type":"9","type":"2","car_type_name":"商务型","rank":4}]
     * 】
     */
    public function getCarType(){
        $goType      = input('go_type',0);
        $useType     = input('use_type',0);//备用
        if($goType==0){
            return $this->retError(128);
        }
        $carType = (new model\CarType())->getType($goType,$useType);
        return $this->retSucc(['data'=>$carType]);
    }

    /**
     * @name【个人计费信息】
     * @desc【个人计费信息】
     * @uri【use_car_daily】
     * @method【post】
     * @param【
     * ptoken $ string $ token $ 校验码 $ 1#
     * type $ string $ 1 $ 类型。4：约组车，2：公务车，5：私包车，3：公包车 $ 1#
     * car_type $ string $ 1 $ 车辆类型，2：优选型，3：舒适型，4：豪华型，5：小巴，6：中巴，7：大巴，8：执法车 $ 1#
     * estimate_mileage $ string $ 1 $ 公里数 $ 1#
     * estimate_time $ int $ 1 $ 用时间秒 #
     * order_type $ string $ 1 $ 订单类型 $ 1#
     * is_return $ string $ 1 $ order_type=1,是否往返
     * 】
     * @return【
     * code $ int $ number|1-1 $ 标识1-成功 0-失败#
     * msg $ string $  $ code=0，错误信息
     * 】
     */
    public function use_car_daily()
    {
        $string         = 'type#用车类型@require|in:2,3,4,5/car_type#车型@require|in:2,3,4,5,6,7,8,9';
        $car_type_where = $this->getBatchParam($string);
        $car_type_where['state']    = 1;   //启用   2-禁用
        $string   = 'estimate_mileage|0|mile#里程@require|float/estimate_time|0|time#时间@number/is_return|9#是否返程@require|in:1,9';
        $data     = $this->getBatchParam($string);
        $car_info = Db::name('car_type')->where($car_type_where)->whereNull('delete_time')->find();
        if (!$car_info) {
            return $this->retError('无该车辆类型/已停用！');
        }
        $cost_info = (new model\OrderFee())->countPreFee($car_info,$data['mile']*1000,$data['time'],$data['is_return']);
        $code      = empty($cost_info) ? 0 : 1;
        $msg       = empty($cost_info) ? '计算车费出错' : $cost_info;
        return $this->retAll($code,$msg);
    }

    /**
     * @name【评价-评星】
     * @desc【评价-评星】
     * @uri【evaluation_star】
     * @method【post】
     * @param【
     * ptoken $ string $ token $ 校验码 $ 1 #
     * evaluation $ string $ 服务棒 $ 评价内容 #
     * evaluate_tag $ string $ 标签 $ 标签内容 #
     * star $ string $ 5 $ 评星 $ 1 #
     * order_id $ string $ 15198 $ 订单号 $ 1
     * 】
     * @return【
     * code $ int $ number|1-1 $ 标识1-成功 0-失败#
     * msg $ string $  $ code=0，错误信息
     * 】
     */
    public function evaluation_star()
    {
        $data['evaluate']    = input('evaluation','');
        $data['star']        = input('star');
        $data['evaluate_tag']= input('evaluate_tag','');
        if(!$data['star']){
            return $this->retError(137);
        }
        $data['order_state'] = 11;
        $oid = input('order_id');
        $osn = input('order_no');
        $oid && $where['order_id'] = $oid;
        $osn && $where['order_no'] = $osn;
        $resl = Db::name('order')->where($where)->update($data);
        if ($resl) {
            return $this->retSucc();
        } else {
            return $this->retError('系统异常，评价出错！');
        }
    }

    /**
     * @name【评星内容】
     * @desc【评星内容】
     * @uri【evaluateDriver】
     * @method【post】
     * @param【
     * ptoken $ string $ token $ 校验码 $ 1 #
     * order_id $ int $ 15198 $ 订单id $ 1
     * 】
     * @return【
     * code $ int $ number|1-1 $ 标识1-成功 0-失败#
     * msg $ string $  $ code=0，错误信息 #
     * data $ json $ $ 数据 $ [{"star":1,"desc":"非常差","tags":["很差","绕路","态度不好","人车不符合"]},{"star":2,"desc":"不好","tags":["态度不行","车况不好"]},{"star":3,"desc":"一般","tags":["态度一般","还行"]},{"star":4,"desc":"不错哦","tags":["很棒","风趣"]},{"star":5,"desc":"太棒咯，赞一个","tags":["很棒","风趣"]}]
     * 】
     */
    public function evaluateDriver(){
        $tag  = ['很差','绕路','态度不好','人车不符合'];
        $base = [
                'star'=> 1,
                'desc' => '非常差',
                'tags' => $tag
            ];
        $data[] = $base;
        $base['star'] = 2;
        $base['desc'] = '不好';
        $base['tags'] = ['态度不行','车况不好'];
        $data[] = $base;
        $base['star'] = 3;
        $base['desc'] = '一般';
        $base['tags'] = ['态度一般','还行'];
        $data[] = $base;
        $base['star'] = 4;
        $base['desc'] = '不错哦';
        $base['tags'] = ['很棒','风趣'];
        $data[] = $base;
        $base['star'] = 5;
        $base['desc'] = '太棒咯，赞一个';
        $base['tags'] = ['很棒','风趣'];
        $data[] = $base;
        return $this->retSucc(['data'=>$data]);
    }

    /**
     * @name【绑定推送】
     * @desc【绑定推送】
     * @uri【addBind】
     * @method【post】
     * @param【
     * ptoken $ string $ token $ 校验码 $ 1#
     * passenger_id $ int $ 1 $ 乘客id $ 1 #
     * push_user_id $ string $ abcdasdfasdfaf $ 极光用户标识id $ 1 #
     * device_token $ string $ abac $ 设备唯一标识 $ 1#
     * pkg_name $ string $ xdg.1233 $ 包名$ 1#
     * device_brand $ string $ 小米 $ 设备品牌 $ 1#
     * device_model $ string $ 2S $ 设备型号 $ 1#
     * device_version $ string $ 8 $系统版本 $1 #
     * device_type $ int $ 1 $ 设备类型 1安卓 2苹果
     * 】
     * @return【
     * code $ int $ number|1-1 $ 校验码#
     * msg $ string $  $ 错误信息
     * 】
     * @throws \think\exception\DbException
     */
    public function addBind()
    {
        $data['push_user_id']   = input('push_user_id');
        $data['device_token']   = input('device_token');
        $data['device_type']    = input('device_type');
        $data['pkg_name']       = input('pkg_name');
        $data['device_brand']   = input('device_brand');
        $data['device_model']   = input('device_model');
        $data['device_version'] = input('device_version');
        $data['use_type']       = 2;
        $user_id                = $this->passengerInfo['user_id'];
        if ($user_id == 0) {
            return $this->retError('无乘客信息！');
        }
        $exist    = model\PushBind::get(['user_id' => $user_id,'use_type'=>2]);
        $pushBind = new model\PushBind();
        $pushBind->save(['push_user_id'=>''],['push_user_id'=>$data['push_user_id'],'use_type'=>2]);
        if (!empty($exist)) {
            $pushBind = new model\PushBind();
            $pushBind->save($data, ['user_id' => $user_id,'use_type'=>2]);
            $msg   = $data['device_brand'].$data['device_model'];
            $param = ['type'=>'passenger','id'=>$exist->push_user_id,'pid'=>$this->passengerInfo['passenger_id'],'msg'=>$msg];
            Hook::listen('change_device',$param);
            return $this->retSucc();
        } else {
            $data['user_id'] = $user_id;
            $pushBind        = new model\PushBind();
            if ($pushBind->validate(true)->save($data)) {
                return $this->retSucc();
            } else {
                return $this->retError($pushBind->getError());
            }
        }
    }

    /**
     * @name【获取隐号】
     * @desc【获取隐号】
     * @uri【getHidePhone】
     * @method【post】
     * @param【
     *  ptoken  $ string $ token $ 校验 $ 1 #
     *  orderid $ int $ 1 $ 订单id $ 1 #
     *  phone1  $ string $ 15559203611 $ 主叫号码 $ 1 #
     *  phone2  $ string $ 15559203611 $ 被叫号码 $ 1
     * 】
     * @return【
     * code $ int    $ number|1-1 $ 校验码#
     * msg  $ string $  $ 错误信息
     * 】
     */
    public function getHidePhone(){
        $phone1 = input('phone1');
        $phone2 = input('phone2');
        $oid    = input('orderid');
        $phone  = (new Phone())->dial_get($phone1,$phone2,$oid);
        if($phone==0 || $phone=='0'){
            return $this->retError(124);
        }
        return $this->retSucc(['data'=>$phone]);
    }

    /**
     * @name【到达后支付】
     * @desc【到达后支付】
     * @uri【order_pay】
     * @method【post】
     * @param【
     * ptoken   $ string $ token $ 校验码 $ 1#
     * orderid $ string $ 1 $ 订单id $ 1
     * 】
     * @return【
     * code $ int $ number|1-1 $ 标识1-成功 0-失败#
     * msg $ string $  $ code=0，错误信息
     * 】
     */
    public function order_pay()
    {        $oid   = input('orderid', 0);
        $order = model\Order::get($oid);
        $pid   = $this->passengerInfo['passenger_id'];
        if (!$order || $order->passenger_id != $pid) {
            return $this->retError(404);
        }
        if ($order->order_state != 9) {
            return $this->retError('该订单尚未完成');
        }
        $fee      = model\OrderFee::get(['order_id' => $oid]);
        $money    = $fee->passenger_money ? floatval($fee->passenger_money) : 0;
        $payType  = $order->pay_type;
        list($code,$leftPay) = (new model\Passenger())->orderPay($oid,$pid,$money,$payType);
        if($code==1){
            Hook::listen('pay_order',$oid);
            return $this->retSucc();
        }else{
            $money = floatval($leftPay)*100;
            if($money==0){
                return $this->retError('额度不足');
            }
            list($code, $data) = (new WechatPay())->makeWeChatPay('订单支付',  '晋江出行', $order->order_no, $money);
            return $this->retAll($code,$data);
        }
    }

    /**
     * @name【进行审批操作】
     * @desc【进行审批操作】
     * @uri【approval_opration】
     * @method【post】
     * @param【
     * ptoken $ string $ token $ 校验码 $ 1#
     * order_id $ int $ 1 $ 订单id $ 1 #
     * order_state $ string $ 2 $ 订单状态2-批准 3-驳回 $ 1 #
     * reject_note $ string $ 拒绝 $ 驳回理由
     * 】
     * @return【
     * code $ int $ number|1-1 $ 标识1-成功 0-失败#
     * msg $ string $  $ code=0，错误信息
     * 】
     */
    public function approval_opration()
    {
        $oid        = input('order_id',0);
        $osn        = input('order_no','');
        $oid        = $oid == 0 ? $osn : $oid;
        $orderState = input('order_state',2);
        $note       = input('reject_note','');
        list($code,$msg) = (new \app\api\logic\Order())->approvalOrder($this->passengerInfo['passenger_id'],$oid,$orderState,$note);
        return $this->retAll($code,$msg);
    }

    /**
     * @name【获取四办司机车辆】
     * @desc【获取四办司机车辆】
     * @uri【getLeaderDrivers】
     * @method【post】
     * @param【
     * ptoken $ string $ token $ 校验码 $ 1#
     * order_id $ int $ 1 $ 订单id $ 1
     * 】
     * @return【
     * code $ int $ number|1-1 $ 标识1-成功 0-失败#
     * msg $ string $  $ code=0，错误信息 #
     * data $ json $ $ 司机列表 $ {"driver":[{"driver_id":17,"user_id":7,"name":"帅哥","phone":"13959203611","head_img":"upload\/driver\/img\/head_img\/20180328\/de6c8816d47ff84ca93255c6b6db217d.jpge","work_state":4,"lon":"118.1582297092","lat":"24.477687717014","update_time":"2018-04-19 19:52:53","car_id":406,"star":"4.8","score":"98.60","rate":"99.00","default_car_type":"4-3","default_prop":"","car_type_id":138,"cars":"134,138","other_type":{"134":379,"138":406},"car_types":{"2-9":379,"4-3":406},"prop":{"4":379},"activeTime":1524209130,"loginTime":1524209130,"gps_time":1524209130,"area_id":4,"distance":51928.777449324,"rece_car":null}],"spare_driver":[{"driver_id":17,"user_id":7,"name":"帅哥","phone":"13959203611","head_img":"upload\/driver\/img\/head_img\/20180328\/de6c8816d47ff84ca93255c6b6db217d.jpge","work_state":4,"lon":"118.1582297092","lat":"24.477687717014","update_time":"2018-04-19 19:52:53","car_id":406,"star":"4.8","score":"98.60","rate":"99.00","default_car_type":"4-3","default_prop":"","car_type_id":138,"cars":"134,138","other_type":{"134":379,"138":406},"car_types":{"2-9":379,"4-3":406},"prop":{"4":379},"activeTime":1524209130,"loginTime":1524209130,"gps_time":1524209130,"area_id":4,"distance":51928.777449324,"rece_car":null}]}
     * 】
     */
    public function getLeaderDrivers(){
        if($this->passengerInfo['prop']<>13) return $this->retError(134);
        $oid     = input('order_id',0);
        $drivers = (new Driver())->getLearDrivers($oid);
        $data['data']        = $drivers;
        $string = 'driver|首选司机,spare_driver|备选司机,driver_id|司机id';
        $data['description'] = analyzeDesc($string);
        return $this->retSucc(['data'=>$drivers]);
    }

    /**
     * @name【四办派车】
     * @desc【四办派车】
     * @uri【selectDriverCar】
     * @method【post】
     * @param【
     * ptoken $ string $ token $ 校验码 $ 1#
     * order_id $ int $ 1 $ 订单id $ 1 #
     * driver_id $ int $ 1 $司机id $ 1#
     * car_id $ int $ 1$车辆id $1
     * 】
     * @return【
     * code $ int $ number|1-1 $ 标识1-成功 0-失败 #
     * msg $ string $  $ code=0，错误信息
     * 】
     */
    public function selectDriverCar(){
        $string = 'order_id#订单@require|number/driver_id#司机@require|number/';
        $string.= 'car_id#车辆@require|number/is_return';
        $data   = $this->getBatchParam($string);
        $result = (new Driver())->receiveOrder($data['driver_id'],$data['order_id'],$data['car_id'],2);
        return $this->retAll($result[0],$result[1]);
    }

    /**
     * @name【车型列表-新UI】
     * @desc【车型列表-新UI】
     * @uri【getNewCarType】
     * @method【post】
     * @param【
     * ptoken $ string $ token $ 校验码 $ 1
     * 】
     * @return【
     * code $ int $ number|1-1 $ 标识1-成功 0-失败 #
     * msg $ string $  $ code=0，错误信息 #
     * data $ json $$ 数据 $ {"2":{"name":"巴士","type":{"2":[{"car_type_id":82,"car_type_name":"公务车小巴(11座)","type":"2","car_type":"6","seats":11,"chartered_km":0,"chartered_hour":0,"chartered_charge":"0.00"},{"car_type_id":153,"car_type_name":"公务车大巴(座)","type":"2","car_type":"5","seats":0,"chartered_km":0,"chartered_hour":null,"chartered_charge":null},{"car_type_id":154,"car_type_name":"公务车大巴(35座)","type":"2","car_type":"5","seats":35,"chartered_km":0,"chartered_hour":null,"chartered_charge":null}],"3":[{"car_type_id":101,"car_type_name":"公包车小巴(11座)-4小时","type":"3","car_type":"6","seats":11,"chartered_km":100,"chartered_hour":4,"chartered_charge":"350.00"},{"car_type_id":102,"car_type_name":"公包车小巴(11座)-10小时","type":"3","car_type":"6","seats":11,"chartered_km":300,"chartered_hour":10,"chartered_charge":"630.00"},{"car_type_id":129,"car_type_name":"公包车小巴(11座)-6小时","type":"3","car_type":"6","seats":11,"chartered_km":200,"chartered_hour":6,"chartered_charge":"500.00"},{"car_type_id":130,"car_type_name":"公包车小巴(11座)-2小时","type":"3","car_type":"6","seats":11,"chartered_km":40,"chartered_hour":2,"chartered_charge":"200.00"},{"car_type_id":152,"car_type_name":"公包车小巴(12座)-2小时","type":"3","car_type":"6","seats":12,"chartered_km":33,"chartered_hour":null,"chartered_charge":null}]}},"3":{"name":"行政执法"}}
     * 】
     */
    public function getNewCarType(){
        $where['state'] = 1;
        $field = 'car_type_id,car_type_name,type,car_type,seats,chartered_km,chartered_hour,p_chartered_charge as chartered_charge';
        $carTypes = Db::name('car_type')->where($where)->whereNull('delete_time')->field($field)->select();
        $data = [];
        $data['2']['name'] = '巴士';
        $data['2']['rank'] = 3;
        $data['2']['desc'] = 'bus';
        $data['2']['code'] = 2;
        $data['0']['name'] = '快车';
        $data['0']['rank'] = 1;
        $data['0']['desc'] = 'fast';
        $data['0']['code'] = 0;
        $data['1']['name'] = '专车';
        $data['1']['rank'] = 2;
        $data['1']['desc'] = 'tailored';
        $data['1']['code'] = 1;
        $data['3']['name'] = '行政执法';
        $data['3']['rank'] = 4;
        $data['3']['desc'] = 'law';
        $data['3']['code'] = 3;
        foreach ($carTypes as $carType){
            if($carType['car_type']==2){
                $type = $carType['type'];
                $data[0]['type'][$type][] = $carType;
            }
            if(in_array($carType['car_type'],[3,4,9])){
                $type = $carType['type'];
                $data[1]['type'][$type][] = $carType;
            }
            if(in_array($carType['car_type'],[5,6,7])){
                $type = $carType['type'];
                $data[2]['type'][$type][] = $carType;
            }
        }
        $dataNew[] = $data['0'];
        $dataNew[] = $data['1'];
        $dataNew[] = $data['2'];
        $dataNew[] = $data['3'];
        return $this->retSucc(['data'=>$dataNew]);
    }

    /**
     * @name【版本检查】
     * @desc【版本检查】
     * @uri【getVersion】
     * @method【post】
     * @param【
     *  ptoken $ string $ token $ 校验 $ 1
     * 】
     * @return【
     * code $ int    $ number|1-1 $ 校验码#
     * msg  $ string $  $ 错误信息 #
     * android_version $ string $ $ 版本号 #
     * android_version_name $ string $$ 版本名#
     * url $ string $ $下载地址 #
     * oss_url $ string $ $OSS下载地址 #
     * update_time $ datetime $$更新日期
     * 】
     */
    public function getVersion(){
        $version = (new Version())->checkVersion('passenger_app');
        return $this->retSucc($version);
    }
}